package Collection;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

/**
 * map例子
 * Created by Administrator on 2017/6/8.
 */
public class MapDemo {
    public static void main(String[] args) {
        /**
         * map接口没有add()方法.
         * 要放置元素通过put()方法.
         * 获取元素的时候
         * Object get(Object key)
         * 通过键获取值
         * Hash表,通过键计算出相对应的存储位置的值,并输出.
         */

        HashMap hm = new HashMap();
        hm.put("1", "zhangsan");
        hm.put("2", "lisi");
        hm.put("3", "wangwu");

        System.out.println(hm.get("1"));
        System.out.println(hm.get("2"));
        System.out.println(hm.get("3"));

        Set keys = hm.keySet();
        Collection values = hm.values();

        Iterator it = keys.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }

    }
}
